package com.rkc.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author `RKC`
 * @date 2021/10/23 16:18
 */
@Data
@Configuration
public class RedissonConfiguration {

    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private int redisPort;

    @Value("${spring.redis.password}")
    private String redisPassword;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        //多点集群方式
//        config.useClusterServers().addNodeAddress("redis://192.168.1.3:6379", "redis://192.168.1.4:6379")
        config.useSingleServer().setPassword(redisPassword).setAddress("redis://" + redisHost + ":" + redisPort);
        return Redisson.create(config);
    }
}
